home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / gfx / x11 / oldXlib.lha / oldXlib / src / lib / oldX / XLookAssoc.c < prev    next >
C/C++ Source or Header  |  1994-04-18  |  3KB  |  77 lines

  1. /* $XConsortium: XLookAssoc.c,v 10.18 94/04/17 20:11:37 rws Exp $ */
  2. /*
  3.  
  4. Copyright (c) 1985  X Consortium
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12.  
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  19. X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  20. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22.  
  23. Except as contained in this notice, the name of the X Consortium shall not be
  24. used in advertising or otherwise to promote the sale, use or other dealings
  25. in this Software without prior written authorization from the X Consortium.
  26.  
  27. */
  28.  
  29. #include "Xlibint.h"
  30. #include "X10.h"
  31.  
  32. /* 
  33.  * XLookUpAssoc - Retrieve the data stored in an XAssocTable by its XId.
  34.  * If an appropriately matching XId can be found in the table the routine will
  35.  * return apointer to the data associated with it. If the XId can not be found
  36.  * in the table the routine will return a NULL pointer.  All XId's are relative
  37.  * to the currently active Display.
  38.  */
  39. XPointer XLookUpAssoc(dpy, table, x_id)
  40.         register Display *dpy;
  41.     register XAssocTable *table;    /* XAssocTable to search in. */
  42.     register XID x_id;            /* XId to search for. */
  43. {
  44.     int hash;
  45.     register XAssoc *bucket;
  46.     register XAssoc *Entry;
  47.  
  48.     /* Hash the XId to get the bucket number. */
  49.     hash = x_id & (table->size - 1);
  50.     /* Look up the bucket to get the entries in that bucket. */
  51.     bucket = &table->buckets[hash];
  52.     /* Get the first entry in the bucket. */
  53.     Entry = bucket->next;
  54.  
  55.     /* Scan through the entries in the bucket for the right XId. */
  56.     for (; Entry != bucket; Entry = Entry->next) {
  57.         if (Entry->x_id == x_id) {
  58.             /* We have the right XId. */
  59.             if (Entry->display == dpy) {
  60.                 /* We have the right display. */
  61.                 /* We have the right entry! */
  62.                 return(Entry->data);
  63.             }
  64.             /* Oops, identical XId's on different displays! */
  65.             continue;
  66.         }
  67.         if (Entry->x_id > x_id) {
  68.             /* We have gone past where it should be. */
  69.             /* It is apparently not in the table. */
  70.             return(NULL);
  71.         }
  72.     }
  73.     /* It is apparently not in the table. */
  74.     return(NULL);
  75. }
  76.  
  77.